home *** CD-ROM | disk | FTP | other *** search
- Path: news.smallworld.co.uk!arthur
- From: arthur@Smallworld.co.uk (Arthur Chance)
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Subject: Re: Access carry flag from C
- Date: 20 Feb 1996 14:34:03 GMT
- Organization: Smallworldwide
- Message-ID: <ARTHUR.96Feb20143404@gold.Smallworld.co.uk>
- References: <Dn1C9z.DGv.0.net@indra.com>
- <1996Feb1922.17.19.879@koobera.math.uic.edu> <31298D20.41C6@bazis.nl>
- NNTP-Posting-Host: gold.smallworld.co.uk
- In-reply-to: Franz Korntner's message of Tue, 20 Feb 1996 08:58:08 GMT
-
- In article <31298D20.41C6@bazis.nl> Franz Korntner <fkorntne@bazis.nl> writes:
- > j+k will overflow when the result exceeds MAXINT
- >
- > Thus: "if (j+k > MAXINT) overflow();" but the operation is undefined
- > if the result overflows, so the expression needs rewriting to make sure
- > this doesn't happen. The result is then "if (j>MAXINT-k) overflow();".
-
- As we must be talking about signed ints, because unsigned can't cause
- undefined behaviour by overflow, if k < 0, then MAXINT-k overflows.
-
- Basically, the C *standard* is useless on things like signed overflow
- (or word size, or what happens with right shift of -ve numbers, or
- <insert your favourite "undefined behaviour" gripe here>). You have
- to look carefully at each *implementation* you use. You can usually
- find some way to do what you want, but you have to accept it's never,
- ever going to be standard C.
-
- --
- You cannot hope to bribe or twist/thank God! the British journalist.
- But, seeing what the man will do/unbribed, there's no occasion to.
- -- Humbert Wolfe 1886-1940
-